"""
    1. 找到变换矩阵
        cv.getPerspectiveTransform()
    2. 变换
        cv.warpPerspective()
"""
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

# 1. 读取图像
img = cv.imread("image/img.png")

# 2. 透射变换
rows, cols = img.shape[:2]
# 2.1 创建变换矩阵
pts1 = np.float32([[56, 65], [368, 52], [28, 387], [389, 390]])
pts2 = np.float32([[100, 154], [300, 100], [80, 290], [310, 300]])

T = cv.getPerspectiveTransform(pts1, pts2)
# 2.2 进行变换
dst = cv.warpPerspective(img, T, (cols, rows))

# 3. 图像展示
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 8), dpi=100)
axes[0].imshow(img[:, :, ::-1])
axes[0].set_title("原图")
axes[1].imshow(dst[:, :, ::-1])
axes[1].set_title("透射后结果")
plt.show()

